/*--------------------------------------------------------------------------------*/
#ifndef __GRAPHIC_IMAGE__
#define __GRAPHIC_IMAGE__
/*--------------------------------------------------------------------------------*/
#include "primitives.h"
#include "object.h"
#include "util.h"
#include "ref_to_.h"
#include "array.h"
#include "color.h"
#include "debug.h"
#include <GL/gl.h>
/*--------------------------------------------------------------------------------*/
enum GRAPHIC_IMAGE_FORMAT
{
	GRAPHIC_IMAGE_FORMAT_Rgb = GL_RGB,
	GRAPHIC_IMAGE_FORMAT_Rgba = GL_RGBA
};
/*--------------------------------------------------------------------------------*/
class GRAPHIC_IMAGE : public OBJECT
{

public:

    DECLARE_REF( GRAPHIC_IMAGE );

    // .. CONSTRUCTORS

    GRAPHIC_IMAGE() : OBJECT(), ByteTable(), Height(0), Width(0), BytesPerPixel(0), Format()
    {
    }

    virtual ~GRAPHIC_IMAGE()
    {
    }

    // .. METHODS

    VOID SetWidth( const COUNT width )
    {
    	Width = width;
    }

    VOID SetHeight( const COUNT height )
    {
    	Height = height;
    }

    VOID SetBytesPerPixel( const UINT8 bpp )
    {
    	BytesPerPixel = bpp;
    }

    VOID SetFormat( const GRAPHIC_IMAGE_FORMAT format )
    {
    	Format = format;
    }

    VOID AddByte( const UBYTE byte )
    {
    	ByteTable.Add( byte );
    }

    const UBYTE * GetArray() const
	{
    	return &ByteTable[0];
	}

    GRAPHIC_IMAGE_FORMAT GetFormat()
    {
    	return Format;
    }

    COUNT GetBytesPerPixel() const
    {
    	return BytesPerPixel;
    }

    COUNT GetHeight() const
    {
    	return Height;
    }

    COUNT GetWidth() const
    {
    	return Width;
    }

    VOID VerticalFlip()
    {
    	ARRAY<UBYTE>
			current_byte_table = ByteTable;
    	INDEX
			x_index,
			y_index,
			byte_offset;

    	for_each_index( x_index, Width )
    	{
			for_each_index( y_index, Height )
			{
				for_each_index( byte_offset, BytesPerPixel )
				{
					ByteTable[ ( ( Height - y_index - 1 ) * Width + x_index ) * BytesPerPixel + byte_offset ] = current_byte_table[ ( y_index * Width + x_index ) * BytesPerPixel + byte_offset ];
				}
			}
    	}
    }

    // -- PRIVATE

private :

    // .. ATTRIBUTES

    ARRAY<UBYTE>
		ByteTable;
    COUNT
		Height,
		Width;
    UINT8
		BytesPerPixel;
    GRAPHIC_IMAGE_FORMAT
		Format;

    
};
/*--------------------------------------------------------------------------------*/
#endif
